﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Boiling.BizFacade
{
    using System;
    using System.Data;

    using Boiling.Common;
    using Boiling.DataAccess;


    public class c_Mes
    {
        public String mesID;
        public String mesHostID;
        public String mesGuestID;
        public String mesContent;
        public String mesDate;
    }
    


    /// <summary>
    /// 管理主页留言
    /// </summary>
    public class GossipManager
    {
        /// <summary>
        /// 输入一个用户的注册邮箱，返回其页面的留言列表
        /// </summary>
        /// <param name="hostID">用户邮箱</param>
        /// <returns></returns>
        public b_Page_Mesdata GetGossipsbyID(String hostID)
        {
            return (new b_Page_Mes()).getpagemesbyID(hostID);
        }

        public c_Mes[] GetGossipsbyIDReturnClass(String hostID)
        {
            int n = GetUserGossipCount(hostID);
            c_Mes[] mes = new c_Mes[n];
            b_Page_Mesdata mesdata = new b_Page_Mesdata();
            mesdata = GetGossipsbyID(hostID);
            for (int i = 0; i < n; i++ )
            {
                mes[i] = new c_Mes();
                mes[i].mesHostID = mesdata.Tables[b_Page_Mesdata.b_Page_Mes_Table].Rows[0][b_Page_Mesdata.Host_User_ID_Field].ToString();
                mes[i].mesGuestID = mesdata.Tables[b_Page_Mesdata.b_Page_Mes_Table].Rows[0][b_Page_Mesdata.Guest_User_ID_Field].ToString();
                mes[i].mesDate = mesdata.Tables[b_Page_Mesdata.b_Page_Mes_Table].Rows[0][b_Page_Mesdata.Mes_Date_Field].ToString();
                mes[i].mesContent = mesdata.Tables[b_Page_Mesdata.b_Page_Mes_Table].Rows[0][b_Page_Mesdata.Mes_Content_Field].ToString();
            }
            return mes;
        }








        /// <summary>
        /// 输入一个用户的注册邮箱，返回其页面的留言总数
        /// </summary>
        /// <param name="hostID">用户邮箱</param>
        /// <returns></returns>
        public int GetUserGossipCount(String hostID)
        {
            return(new b_Page_Mes()).countmesbyname(hostID);
        }

        /// <summary>
        /// 根据页面留言编号删除一篇留言
        /// </summary>
        /// <param name="mesid"></param>
        /// <returns></returns>
        public bool deletemesbyNO(int mesid)
        {
            return (new b_Page_Mes()).deletemesbyNO(mesid);
        }

        /// <summary>
        /// 删除一个留言
        /// </summary>
        /// <param name="hostID">用户ID</param>
        /// <returns></returns>
        public bool DeleteGossipsbyID(String hostID)
        {
            return (new b_Page_Mes()).deletemesbyname(hostID);
        }


        /// <summary>
        /// 增加一条页面留言
        /// </summary>
        /// <param name="hostID">留言发布者id</param>
        /// <param name="guestID">被回复的留言拥有者id</param>
        /// <param name="content">留言内容</param>
        /// <returns></returns>
        public bool InsertGossip(String hostID, String guestID, String content)
        {
            b_Page_Mesdata gossipData = new b_Page_Mesdata();
            DataTable table = gossipData.Tables[b_Page_Mesdata.b_Page_Mes_Table];
            DataRow row = table.NewRow();

            row[b_Page_Mesdata.Guest_User_ID_Field] = guestID;
            row[b_Page_Mesdata.Host_User_ID_Field] = hostID;
            row[b_Page_Mesdata.Mes_Content_Field] = content;
            row[b_Page_Mesdata.Mes_Date_Field] = System.DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒");

            table.Rows.Add(row);
            
            return true;
        }
    }
}
